package com.cqhilink.iot.jobstandardmanagement.services.innerservice.impl.operateunit;
import com.cqhilink.iot.jobstandardmanagement.dao.mapper.ReportItemMapper;
import com.cqhilink.iot.jobstandardmanagement.facade.model.ReportItem;
import com.cqhilink.iot.jobstandardmanagement.facade.model.Ztree;
import com.cqhilink.iot.jobstandardmanagement.facade.service.operateunit.JsmReportItemService;
import com.cqhilink.iot.jobstandardmanagement.facade.utils.TreeIconSkin;
import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄学乾 778142659@qq.com
 * @create 2017-08-24 17:34
 **/
public class JsmReportItemServiceImpl implements JsmReportItemService {
    @Autowired(required = false)
    private ReportItemMapper reportItemMapper ;

    /**
     * @param itemId 数据项
     * @return
     * @throws Exception
     */
    @Override
    public ReportItem queryReportItem(String itemId) throws Exception {
        return reportItemMapper.selectByPrimaryKey(itemId);
    }

    /**
     * @param reportItems 一线场站手工录入系统数据项集合转树
     * @return
     * @throws Exception
     */
    @Override
    public List<Ztree> offsetReportItem(List<ReportItem> reportItems) throws Exception {
        List<Ztree> ztreeList =  new ArrayList<>() ;
        // 将一线场站的数据项配置 ，查询进行配置
        if(reportItems != null && reportItems.size() > 0){
            // 询换转换树形结构
            for(ReportItem reportItem : reportItems){
                // 树形数据转换
                Ztree  ztree = new Ztree();
                ztree.setId(reportItem.getItemId());
                ztree.setName(reportItem.getItemName());
                ztree.setpId(reportItem.getReportId());
                ztree.setOpen(false);
                ztree.setIconSkin(TreeIconSkin.ICON_DEVICE_CHARA.getDesc());
                ztreeList.add(ztree);
            }
        }
        return ztreeList ;
    }

    /**
     *
     * @param reportId 根据报表项id , 查询数据项
     * @return
     * @throws Exception
     */
    @Override
    public List<ReportItem> findReportItemList(String reportId) throws Exception {
        List<ReportItem> reportItems =  reportItemMapper.findReportItemList(reportId);
        return reportItems ;
    }
}
